package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Faillog;
import cn.wolfcode.crm.query.impl.FaillogQuery;
import cn.wolfcode.crm.service.IFaillogService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("faillog")
public class FaillogController {
    @Autowired
    IFaillogService faillogService;

    @RequestMapping("view")
    public String view() {
        return "faillog";
    }
    @RequestMapping("run")
    public String run() {
        return "run";
    }

    @RequestMapping("getAll")
    @ResponseBody
    public List<Faillog> getAll() {
        return faillogService.selectAll();
    }

    @RequestMapping("save")
    @ResponseBody
    public JSONResult saveOrUpdate(Long id,String text) {
        try {
                faillogService.insert(id,text);
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult(false, "列表更新失败");
        }
        return new JSONResult(true, "恭喜您执行成功");
    }
    @RequestMapping("saverun")
    @ResponseBody
    public JSONResult saverun(Long id,String text) {
        try {
            faillogService.saverun(id,text);
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult(false, "列表更新失败");
        }
        return new JSONResult(true, "恭喜您执行成功");
    }

    @RequestMapping("query")
    @ResponseBody
    public PageResult query(FaillogQuery qo) {
        return faillogService.query(qo);
    }
}
